<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lysee Reference Manual - Expression</title>
<link href="index.css" rel="stylesheet" type="text/css">
<link href="logo.ico" rel="Shortcut Icon">
</head>
<body> 
<table width="760" border="0" align="center" cellpadding="0" cellspacing="8"> 
  <tr> 
    <td align="left" valign="middle"> <table width="100%"  border="0" cellspacing="0" cellpadding="0"> 
        <tr> 
          <td align="left" valign="top"><a href="index.html"><img src="logo.png" width="490" height="70" border="0"></a></td> 
        <td align="right" valign="bottom"><a href="306.html">&lt;PREV</a>&nbsp;&nbsp;<a href="index.html">HOME</a>&nbsp;&nbsp;<a href="308.html">NEXT&gt;</a></td>
        </tr> 
      </table></td> 
  </tr> 
  <tr> 
    <td class="footer_line"><strong>3.7 <a href="index.html">Lysee Reference Manual</a> - </strong><a href="300.html">Language Reference</a> - <strong>Expressions</strong><br>      </td> 
  </tr> 
  <tr> 
    <td><a name="definition" id="definition"></a><strong><strong>3.</strong>7.1 What is expression?</strong><br> 
      <br> 
 Expression is any legal combination of symbols that represents a value:<br>
<br>
<table  border="0" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <th class="bottom_line">Usages</th>
    <th class="bottom_line">Example</th>
    </tr>
  <tr>
    <td align="center" bgcolor="#FFDFFF" class="bottom_line">Assign Value</td>
    <td align="left" class="bottom_left_line"> magic = <span class="lsp_code">sys::random() % 100</span>;</td>
    </tr>
  <tr>
    <td align="center" bgcolor="#FFDFFF" class="bottom_line">Condition</td>
    <td align="left" class="bottom_left_line"><strong>if</strong> <span class="lsp_code">handle != 0</span> <strong>then</strong> throw(&quot;Failed open file&quot;)<strong> end</strong> </td>
    <tr>
    <td align="center" bgcolor="#FFDFFF" class="bottom_line">Constants</td>
    <td align="left" class="bottom_left_line"><span class="lsp_code">&quot;OK&quot;</span>;</td>
    <tr>
    <td align="center" bgcolor="#FFDFFF" class="bottom_line">Call Function </td>
    <td align="left" class="bottom_left_line"><span class="lsp_code">sys::genid()</span>;</td>
    </table><br>
    Expression in Lysee is calculated from left to right. </td>
  </tr> 
  <tr> 
    <td><a name="operator" id="operator"></a><strong><strong>3.</strong>7.2 Operators</strong><br> 
      <br> 
      Operators in Lysee has different priority levels. They are list below from hight to low:<br> 
<br>
      <table  border="0" align="center" cellpadding="4" cellspacing="0">
        <tr>
          <th class="bottom_line">Lysee Operators </th>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">NEG&nbsp;&nbsp;:&nbsp;-&nbsp;&nbsp;&nbsp;|&nbsp;NOT&nbsp;:&nbsp;not&nbsp;|&nbsp;BNOT:&nbsp;~&nbsp;|&nbsp;FMT&nbsp;:&nbsp;@&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|  H</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">MUL&nbsp;&nbsp;:&nbsp;*&nbsp;&nbsp;&nbsp;| DIV&nbsp;:&nbsp;/&nbsp;&nbsp;&nbsp;|&nbsp;MOD&nbsp;:&nbsp;%&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 1</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">ADD&nbsp;&nbsp;:&nbsp;+&nbsp;&nbsp;&nbsp;|&nbsp;DEC&nbsp;:&nbsp;-&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 2</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">BXOR :&nbsp;^&nbsp;&nbsp;&nbsp;|&nbsp;BAND:&nbsp;&amp;&nbsp;&nbsp;&nbsp;|&nbsp;BOR&nbsp;:&nbsp;|&nbsp;|&nbsp;BSHL:&nbsp;&lt;&lt;&nbsp;|&nbsp;BSHR:&nbsp;&gt;&gt;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 3</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">IS&nbsp;&nbsp;&nbsp;:&nbsp;is&nbsp;&nbsp;|&nbsp;AS&nbsp;&nbsp;:&nbsp;as&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|  4</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">EQ&nbsp;&nbsp;&nbsp;:&nbsp;==&nbsp;&nbsp;|&nbsp;NE&nbsp;&nbsp;:&nbsp;!=&nbsp;&nbsp;|&nbsp;LT&nbsp;&nbsp;:&nbsp;&lt;&nbsp;|&nbsp;LE&nbsp;&nbsp;:&nbsp;&lt;=&nbsp;|&nbsp;GT&nbsp;&nbsp;:&nbsp;&gt;&nbsp;&nbsp;|&nbsp;GE:&nbsp;&gt;=&nbsp;|&nbsp;IN: in | AE: === | MP: like | 5</td>
        </tr>
        <tr>
          <td align="left" class="bottom_left_line">AND&nbsp;&nbsp;:&nbsp;and&nbsp;|&nbsp;OR&nbsp;&nbsp;:&nbsp;or&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| L</td>
        </tr>
    </table>      </td> 
  </tr>
  <tr>
    <td><a name="concate" id="concate"></a><strong><strong>3.</strong>7.3 Concatenate Strings </strong><br>
      <br>
Use operator + to concatenate strings, at this time left or right value of + must be string type:<br>
<br>
<table width="600"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td nowrap class="dosprompt">&gt;&gt;&gt;&nbsp;=&nbsp;&quot;hello&quot;&nbsp;+&nbsp;&quot;world&quot;;<br>
helloworld<br>
&gt;&gt;&gt;&nbsp;=&nbsp;&quot;TIME:&nbsp;&quot;&nbsp;+&nbsp;now();<br>
TIME:&nbsp;Fri,&nbsp;18&nbsp;Apr&nbsp;2008&nbsp;18:57:52&nbsp;GMT<br>
&gt;&gt;&gt;</td>
  </tr>
</table></td>
  </tr>
  <tr>
    <td><a name="repeats" id="repeats"></a><strong><strong>3.</strong>7.4 Times Concatenate</strong><br>
      <br>
Use operator * to cocatenate string by specified times. In this case left value must be a string and right value must be a integer, or else <strong>nil</strong> is returned:<br>
<br>
<table width="600"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td nowrap class="dosprompt">&gt;&gt;&gt; = &quot;Aa&quot; * 4;<br>
      AaAaAaAa<br>
      &gt;&gt;&gt; = &quot;Cc&quot; * 1.42;
      <p>&gt;&gt;&gt;</p>      </td>
  </tr>
</table></td>
  </tr>
  <tr>
    <td><a name="redirect" id="redirect"></a><strong><strong>3.</strong>7.5 Shift Left Insert</strong><br>
      <br>
When calculate OBJECT &lt;&lt; VALUE, Lysee interpreter will try to insert/add VALUE into/to OBJECT, and expression result is the object:<br>
<br>
<table width="600"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td nowrap class="dosprompt">&gt;&gt;&gt; cout &lt;&lt; &quot;I love &quot; &lt;&lt; &quot;coding&quot; &lt;&lt; &quot;!&quot;;<br>
      I love coding!<br>
    &gt;&gt;&gt; = varlist() &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; &quot;hello&quot; &lt;&lt; 4;<br>
      [1,2,hello,4]<br>
    &gt;&gt;&gt; = strlist() &lt;&lt; &quot;hello&quot; &lt;&lt; &quot;world&quot;;<br>
      hello<br>
      world<br>
    &gt;&gt;&gt;
</td>
  </tr>
</table>

<br>
Now, the OBJECT should be stream、strlist or varlist.</td>
  </tr>
  <tr>
    <td><a name="varlist" id="varlist"></a><strong><strong>3.</strong>7.6 Define varlist Object </strong><br>
      <br>
Symbol [ and ] are used to define varlist object, [] equals with varlist():<br>
<br>
<table width="600"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td nowrap class="dosprompt">&gt;&gt;&gt; a = [1, 2, 3];<br>      &gt;&gt;&gt; = a;<br>
      [1,2,3]<br>
      &gt;&gt;&gt;
</td>
    <td nowrap class="dosprompt">&gt;&gt;&gt; a = [] &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; 3;<br>
&gt;&gt;&gt; = a;<br>
[1,2,3]<br>
&gt;&gt;&gt;</td>
    <td nowrap class="dosprompt">&gt;&gt;&gt; a = varlist() &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; 3;<br> 
      &gt;&gt;&gt; = a;<br>
[1,2,3]<br>
&gt;&gt;&gt;</td>
  </tr>
</table></td>
  </tr>
  <tr>
    <td><a name="hashed" id="hashed"></a><strong><strong>3.</strong>7.7 Define hashed Object</strong><br>
      <br>
Symbol { and } are used to define hashed object, {} equals with hashed():<br>
<br>
<table width="600"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="50%" nowrap class="dosprompt">&gt;&gt;&gt; a = {&quot;name&quot;: &quot;libudi&quot;,<br>
&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;sex&quot; : &quot;male&quot;,<br>
&nbsp;&nbsp;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;age&quot; : 40};<br>
&gt;&gt;&gt; for s in a.keys do<br>
&nbsp;&nbsp;&gt;&nbsp;&nbsp; = s, a.read(s), eol;<br>
&nbsp;&nbsp;&gt; end;<br>
  age 40<br>
  sex male<br>
  name libudi<br>
&gt;&gt;&gt;</td>
    <td nowrap class="dosprompt">&gt;&gt;&gt; a = hashed();<br>
      &gt;&gt;&gt; a.name = &quot;libudi&quot;;<br>
      &gt;&gt;&gt; a.sex = &quot;male&quot;;<br>
      &gt;&gt;&gt; a.age = 40;<br>
      &gt;&gt;&gt; for s in a.keys do<br>
&nbsp;&nbsp;&gt;&nbsp;&nbsp; = s, a.read(s), eol;<br>
&nbsp;&nbsp;&gt; end;<br>
age 40<br>
sex male<br>
name libudi<br>
&gt;&gt;&gt;</td>
  </tr>
</table></td>
  </tr>
  <tr> 
    <td align="right" class="footer_line"><a href="306.html">&lt;PREV</a>&nbsp;&nbsp;<a href="index.html">HOME</a>&nbsp;&nbsp;<a href="308.html">NEXT&gt;</a></td> 
  </tr> 
</table> 
</body>
</html>
